package com.chenyue.cm.bean;

import com.chenyue.cm.common.constant.ConstantValues;
import com.chenyue.cm.common.utils.StringUtils;
import com.google.common.base.CaseFormat;
import lombok.Data;

import java.util.Map;
import java.util.regex.Matcher;

@Data
public class ColumnBean{
		
		private String columnName ; //字段名
		private String columnRemark ; //字段备注
		private Boolean LIST_SHOW_FLAG ; //列表是否展示
		private String  LIST_SHOW_TYPE ; // 展示类型
		private Boolean FORM_SHOW_FLAG ; //表单是否展示
		private String  FORM_SHOW_TYPE ; //表单展示类型
		private Boolean FORM_RULE_FLAG ; //是否必填校验
		private String  columnDataSource ;
		
		public ColumnBean() {
			super();
		}

		public ColumnBean(Map<String, Object> map) {
			
			String columnName = underlineToCamel(map.get("COLUMN_NAME").toString()) ; //字段名
			String columnRemark = underlineToCamel(map.get("COLUMN_COMMENT").toString()) ; //字段备注
			boolean LIST_SHOW_FLAG = "1".equals(map.get("LIST_SHOW_FLAG"))   ; //列表是否展示
			String LIST_SHOW_TYPE = map.get("LIST_SHOW_TYPE").toString() ; //列表展示类型
			boolean FORM_SHOW_FLAG = "1".equals(map.get("FORM_SHOW_FLAG"))   ; //表单是否展示
			String FORM_SHOW_TYPE = map.get("FORM_SHOW_TYPE").toString() ; //表单元素类型
			boolean FORM_RULE_FLAG = "1".equals(map.get("FORM_RULE_FLAG"))  ; //是否必填
			String columnDataSource = underlineToCamel(map.get("ELEMENT_DATASOURCE").toString()) ; //表单数据源

			this.columnName = columnName;
			this.columnRemark = columnRemark;
			this.LIST_SHOW_FLAG = LIST_SHOW_FLAG;
			this.LIST_SHOW_TYPE = LIST_SHOW_TYPE;
			this.FORM_SHOW_FLAG = FORM_SHOW_FLAG;
			this.FORM_SHOW_TYPE = FORM_SHOW_TYPE;
			this.FORM_RULE_FLAG = FORM_RULE_FLAG;
			this.columnDataSource = columnDataSource;

		}


		
		
		/**
	     * 下划线格式字符串转换为驼峰格式字符串2
	     * 
	     * @param param
	     * @return
	     */
	    public static String underlineToCamel(String param) {
            if (param != null) {
                return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, param);
            }

            if (StringUtils.isEmpty(param)) {
                return "";
            }
            StringBuilder sb = new StringBuilder(param);
            Matcher mc = ConstantValues.COMPILE_WITH_.matcher(param);
            int i = 0;
            while (mc.find()) {
                int position = mc.end() - (i++);
                sb.replace(position - 1, position + 1, sb.substring(position, position + 1).toUpperCase());
            }
            return sb.toString();
            //return param;
        }

		public static void main(String[] args) {
	    	String a = "dada_da";
			System.out.println(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, a)) ;
		}
		
	}
	